package com.example.shutdown_v1.entity;

import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;

/**
 * 告警记录实体
 * 对应数据库表: alarm_record
 */
@Data
@Entity
@Table(name = "alarm_record", indexes = {
    @Index(name = "idx_shop_alarm_time", columnList = "shop_id,alarm_time"),
    @Index(name = "idx_alarm_time", columnList = "alarm_time"),
    @Index(name = "idx_alarm_type", columnList = "alarm_type")
})
public class AlarmRecord {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(name = "shop_id", nullable = false)
    private Long shopId;
    
    @Column(name = "alarm_type", nullable = false, length = 32)
    private String alarmType;
    
    @Column(name = "alarm_level", nullable = false)
    private Integer alarmLevel;
    
    @Column(name = "alarm_content", columnDefinition = "TEXT")
    private String alarmContent;
    
    @Column(name = "related_sensors", columnDefinition = "TEXT")
    private String relatedSensors;
    
    @Column(name = "alarm_time", nullable = false)
    private LocalDateTime alarmTime;
    
    @Column(name = "notification_status")
    private Integer notificationStatus = 0;
    
    @Column(name = "notification_channels")
    private String notificationChannels;
    
    @Column(name = "confirmed")
    private Boolean confirmed = false;
    
    @Column(name = "confirmed_by", length = 64)
    private String confirmedBy;
    
    @Column(name = "confirmed_at")
    private LocalDateTime confirmedAt;
    
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    @PrePersist
    protected void onCreate() {
        createdAt = LocalDateTime.now();
    }
}

